package com.taotao.manage.controller.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.taotao.common.bean.EasyUIResult;
import com.taotao.manage.pojo.Content;
import com.taotao.manage.service.ContentService;

/**
 * Content对外提供API的controller
 * 
 * @author Beck
 *
 */
@RequestMapping("api/content")
@Controller
public class APIContentController {
    @Autowired
    private ContentService contentService;

    /**
     * 根据分类id，分页查询内容 异步 参数: categoryId： 分类id，page：当前页, rows: 每页显示多少条数据 返回：EasyUIResult
     */
    @RequestMapping(value="query", method = RequestMethod.GET)
    public ResponseEntity<EasyUIResult> pageQueryByCategoryId(@RequestParam("categoryId") Long categoryId,
            @RequestParam("page") Integer pageNum, @RequestParam("rows") Integer pageSize) {
        try {
            Content record = new Content();
            record.setCategoryId(categoryId);
            PageInfo<Content> info = contentService.queryPageListByWhere(record, pageNum, pageSize);

            EasyUIResult result = new EasyUIResult(info.getTotal(), info.getList());
            // 200
            return ResponseEntity.status(HttpStatus.OK).body(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 500
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
